using System;
using System.Collections.Generic;
using System.Text;

namespace Umdf.SideShow.Properties
{
    public abstract class Property<T>
    {
        private T _value;
        private Guid _formatId;
        private int _pid;

        protected Property(T value)
        {
            _formatId = GetPropertyId(this.GetType(), out _pid);
            _value = value;
        }

        public Guid FormatId
        {
            get { return _formatId; }
        }

        public int Pid
        {
            get { return _pid; }
        }

        public T Value
        {
            get { return _value; }
        }

        internal static Guid GetPropertyId(Type type, out int pid)
        {
            if (type.IsDefined(typeof(PropertyIdAttribute), true))
            {
                PropertyIdAttribute attr = (PropertyIdAttribute)type.GetCustomAttributes(typeof(PropertyIdAttribute), true)[0];
                pid = attr.Pid;
                return attr.FormatId;
            }
            else
            {
                throw new ArgumentException("The type " + type.FullName + " does not contain a PropertyIdAttribute to identify the SideShow endpoint.");
            }
        }
    }
}
